const express = require("express");
var bodyParser = require("body-parser");
const router = express.Router();
var urlencodedParser = bodyParser.urlencoded({ extended: false });
const Mock = require("mockjs");
router.post("/table", (req, res) => {
  const data = Mock.mock({
    code: 200,
    data: {
      "dataSource|150": [
        {
          "key|+1": 1,
          "activeImgUrl|+1": [
            "https://m15.360buyimg.com/mobilecms/jfs/t1/151773/25/29502/95042/63b341c7Fefc0c160/6a4be6551a062574.jpg!cr_1125x449_0_166!q70.jpg",
            "https://m15.360buyimg.com/mobilecms/jfs/t1/141123/1/33440/129740/63cb317eF49b65e49/b963c71b3925f65b.jpg!cr_1125x449_0_166!q70.jpg",
            "https://m15.360buyimg.com/mobilecms/jfs/t1/215922/40/23549/69927/63722419E5c4ad2ed/d96f0f97a0bad3dc.jpg!cr_1125x449_0_166!q70.jpg",
          ],
          "activeMax|+1": 324, //上限人数
          "applicants|+1": 124, // 报名人数
          activeName: " @cword(8,13)",
          activeStartTime: "@date",
          activeEndTime: "@date",
          activedesc: "@paragraph(1, 3)",
          "activeStatus|0-2": 0,
          "address|+1": ["北京市", "天津市", "河北省", "山西省"],
          business: " @cword(5,8)",
          wx: " @cword(1,5)",
          activeDetail: " @cword(1,5)",
        },
      ],
      total: 150,
      currentPage: 1,
      pageSize: 10,
    },
  });
  res.json(data);
});
router.post("/delete", (req, res) => {
  const data = Mock.mock({
    code: 200,
    message: "success",
  });
  res.json(data);
});
router.post("/adminCreate", urlencodedParser, (req, res) => {
  const { id } = req.body;
  const data = id
    ? {
        code: 200,
        data: {
          message: "更新成功",
        },
      }
    : {
        code: 200,
        data: {
          message: "创建成功",
        },
      };
  res.json(data);
});
router.post("/editActiveData", urlencodedParser, (req, res) => {
  const filterData =
    req.body.editId % 2 == 0
      ? {
          "key|+1": req.body.editId,
          activeImgUrl: [
            {
              uid: "1",
              name: "image.png",
              status: "done",
              url: "https://m15.360buyimg.com/mobilecms/jfs/t1/151773/25/29502/95042/63b341c7Fefc0c160/6a4be6551a062574.jpg!cr_1125x449_0_166!q70.jpg",
            },
            {
              uid: "2",
              name: "image.png",
              status: "done",
              url: "https://m15.360buyimg.com/mobilecms/jfs/t1/215922/40/23549/69927/63722419E5c4ad2ed/d96f0f97a0bad3dc.jpg!cr_1125x449_0_166!q70.jpg",
            },
            {
              uid: "3",
              name: "image.png",
              status: "done",
              url: "https://m15.360buyimg.com/mobilecms/jfs/t1/141123/1/33440/129740/63cb317eF49b65e49/b963c71b3925f65b.jpg!cr_1125x449_0_166!q70.jpg",
            },
          ],
          "activeMax|+1": 324, //上限人数
          "applicants|+1": 124, // 报名人数
          activeName: " @cword(8,13)",
          activeStartTime: "@date",
          activeEndTime: "@date",
          activedesc: "@paragraph(1, 3)",
          "activeStatus|0-2": 0,
          "address|+1": ["北京市", "天津市", "河北省", "山西省"],
          business: " @cword(5,8)",
          wx: " @cword(1,5)",
          activeDetail: " @cword(1,5)",
        }
      : {
          "key|+1": req.body.editId,
          activeImgUrl: [
            {
              uid: "1",
              name: "image.png",
              status: "done",
              url: "https://m15.360buyimg.com/mobilecms/jfs/t1/151773/25/29502/95042/63b341c7Fefc0c160/6a4be6551a062574.jpg!cr_1125x449_0_166!q70.jpg",
            },
          ],
          "activeMax|+1": 324, //上限人数
          "applicants|+1": 124, // 报名人数
          activeName: " @cword(8,13)",
          activeStartTime: "@date",
          activeEndTime: "@date",
          activedesc: "@paragraph(1, 3)",
          "activeStatus|0-2": 0,
          "address|+1": ["北京市", "天津市", "河北省", "山西省"],
          business: " @cword(5,8)",
          wx: " @cword(1,5)",
          activeDetail: " @cword(1,5)",
        };
  const data = Mock.mock({
    code: 200,
    data: {
      data: filterData,
    },
  });
  res.json(data);
});
router.post("/createActiveTable", urlencodedParser, (req, res) => {
  const { id } = req.body;
  const data = id
    ? {
        code: 200,
        data: {
          message: "更新成功",
        },
      }
    : {
        code: 200,
        data: {
          message: "创建成功",
        },
      };
  res.json(data);
});

module.exports = router;
